import request from "@/utils/request";

enum API {
    ALLROLE_URL = '/admin/acl/role/',
    ADDROLE_URL = '/admin/acl/role/save',
    UPDATEROLE_URL = '/admin/acl/role/update',
    ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
    SETPERMISSION_URL = '/admin/acl/permission/doAssign/?',
    DELETEROLE_URL = '/admin/acl/permission/remove/'
}

export const reqAllRole = (page, size, rolename) => request.get(API.ALLROLE_URL + `${page}/${size}/?roleName=${rolename}`)

export const reqAddOrUpdateRole = (data) => {
    if (data.id) {
        return request.put(API.UPDATEROLE_URL, data)
    } else {
        return request.post(API.ADDROLE_URL, data)
    }
}

export const reqAllMenuList = (id) => request.get(API.ALLPERMISSION_URL + id)

export const reqSetPermission = (roleId, permissionId) => request.post(API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionId}`)

export const reqDeleteRole = (id) => request.delete(API.DELETEROLE_URL + id)